//
//  WedingRegistrationCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/11/16.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "WedingRegistrationCell.h"

@implementation WedingRegistrationCell

- (void)awakeFromNib {
    [super awakeFromNib];

    [self.naviControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.WedingRegistrationCellBlock) {
            self.WedingRegistrationCellBlock(WedingRegistrationCellActionType_navi);
        }
    }];
    
    self.itemTelLab.userInteractionEnabled = YES;
    [self.itemTelLab addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.WedingRegistrationCellBlock) {
            self.WedingRegistrationCellBlock(WedingRegistrationCellActionType_call);
        }
    }];

}

- (void)fillCellWithModel:(POIAnnotation *)annotation AndLocation:(CLLocation *)currentLocation{
    
    self.itemTitleLab.text = annotation.poi.name;
    
    CLLocation *current= currentLocation;
    CLLocation *point =[[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude];

    double meters = [current distanceFromLocation:point];
    
    NSString *distance=@"" ;
    
    if (currentLocation.coordinate.latitude > 0 && meters > 0) {
        if (meters <= 1000) {
            distance = [NSString stringWithFormat:@"%.0fm",meters];
        } else {
            distance = [NSString stringWithFormat:@"%.0f公里",meters/1000];
        }
    }

    
    self.itemAddressLab.text = [NSString stringWithFormat:@"%@ %@", distance,annotation.poi.address];
    
    self.itemTelLab.text = annotation.poi.tel;
    
    if (annotation.poi.tel.length > 0) {
        self.phoneCallIcon.hidden = NO;
    } else {
        self.phoneCallIcon.hidden = YES;
    }
    
}

@end
